<?php

$latest_rev = $db->fetchOne("SELECT id FROM blog_posts_revisions WHERE post_id=? ORDER BY id DESC LIMIT 1", $_REQUEST['id']);
$db->query("UPDATE blog_posts_revisions SET published=NOW(), published_display=COALESCE(published_display, NOW()) WHERE id=?", $latest_rev);
$db->query("UPDATE blog_posts SET revision_id=?, active=1 WHERE site_id=? AND id=?", array($latest_rev, $site['id'], $_REQUEST['id']));
header('Content-type: application/json');
echo json_encode(array('ok' => true, 'published' => $db->fetchOne("SELECT published_display FROM blog_posts_revisions WHERE id=?", $latest_rev)));